# -*- codeing = utf-8 -*-
# @Time : 2021/2/25 20:54
# @Atuthor: 朱朱
# @File: 105__eq__方法介绍.py
# @Software: PyCharm

class Person(object):
    def __init__(self,name, age):
        self.name = name
        self.age = age

    def __eq__(self, other):
        print('eq方法被调用了,other=',other)
        return self.name == other.name and self.age == other.age

p1 = Person('jack',88)
p2 = Person('jack',77)
p3 = Person('jack',88)
print(id(p1))
print(id(p2))
print(id(p3))

print(p1==p2) # False
print(p1 == p3) # True # 虽然相等,但是内存不一样,所以不是同一个对象
# is 身份运算符 可以用来判断两个对象是否是同一个对象
print(p1 is p2) # False
print(p1 is p3) # False

# __eq__ 如果不重写，默认比较依然是内存地址

# is 比较两个对象的内存地址
# == 会调用对象的 __eq__ 方法，获取这个方法的比较结果
nums1 = [1, 2, 3]
nums2 = [1, 2, 3]
print(nums1 is nums2)  # False
print(nums1 == nums2)  # True